/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/02/18
* File: deserializer.cpp
* Blog: http://www.cnblogs.com/zengqh/
**/

#include "deserializer.h"

namespace HY
{

Deserializer::Deserializer() :
position_(0),
	size_(0)
{
}

Deserializer::Deserializer(unsigned size) :
position_(0),
	size_(size)
{
}

Deserializer::~Deserializer()
{
}


std::string Deserializer::ReadString()
{
	std::string ret;

	for (;;)
	{
		char c;
		ReadBin(c);
		if (!c)
			break;
		else
			ret += c;
	}

	return ret;
}

std::string Deserializer::ReadLine()
{
	std::string ret;

	while (!IsEof())
	{
		char c;
		ReadBin(c);

		if (c == 10)
			break;
		if (c == 13)
		{
			// Peek next char to see if it's 10, and skip it too
			if (!IsEof())
			{
				char next;
				ReadBin(next);
				if (next != 10)
					Seek(position_ - 1);
			}
			break;
		}

		ret += c;
	}

	return ret;
}

}